package taewanme.gae.bookmark.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.google.appengine.api.datastore.Key;

import taewanme.gae.bookmark.dao.BookmarkDaoJDOImpl;
import taewanme.gae.bookmark.dao.UserDaoJDOImpl;
import taewanme.gae.bookmark.model.BookMark;
import taewanme.gae.bookmark.model.User;

@Component("bookmarkService")
public class BookmarkServiceImpl {

	@Resource
	private BookmarkDaoJDOImpl bookMarkDao;
	
	@Resource
	private UserDaoJDOImpl userDao;
	
	public BookMark readBookMark(String url){
		BookMark bookMark = bookMarkDao.get(url);
		Key ownerKey = bookMark.getOwnerKey();
		User owner = userDao.get(ownerKey);
		bookMark.setOwner(owner);
		return bookMark;
	}
	
	public void addBookMark(BookMark bookMark, String email){
		User owner = userDao.get(email);
		bookMark.setOwnerKey(owner.getKey());
		
		bookMarkDao.save(bookMark);
	}
	
	public BookMark dummyGet(){
		BookMark bookMark = new BookMark();
		bookMark.setCreDate(new Date());
		bookMark.setUptDate(new Date());
		bookMark.setUrl("http://www.google.com");
		User owner = userDao.get("bbbbb@gmail.com");
		List<String> tags = new ArrayList<String>();
		tags.add("소마");
		tags.add("클라우드");
		tags.add("앱엔진");
		bookMark.setTags(tags);
		bookMark.setOwnerKey(owner.getKey());
		bookMark.setOwner(owner);
		return bookMark;
	}
}
